Page({
  data:{
    passport:[]
  },
  onLoad(options){
   if(options.id) this.getPassport(options.id)
   if(options.encryptedData) this.getPassportShare(options.encryptedData)
  },
  // 获取通行证
  async  getPassport(id){
     let res = await wx.http.get('/visitor/'+id)
     console.log(res);
    this.setData({passport: res})
  },
  // 分享通行证
  async getPassportShare(encryptedData){
    let res = await wx.http.get('/visitor/share/'+encryptedData)
    this.setData({passport: res})
  },
  // 分享
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData='+this.data.passport.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  // 保存二维码
  saveQRCode(){
    // 读取图片的信息
    wx.getImageInfo({
      src: this.data.passport.url,
      success:(result)=>{
        // 保存到本地
        wx.saveImageToPhotosAlbum({
          filePath: result.path,
        })
      }
    })
  }
})
